<template>
<div class="content" ref="content">

<div class="table-default" v-if="tableData">
  <el-button type="primary" class="backBtn" @click="backHandler">返回</el-button>

  <!-- <div class="search-hidden" ref="searchbox"> -->
    <div id="base" ref="base">
      <el-descriptions :column="3" border title="基本信息">
        <el-descriptions-item label-class-name="labelClassNAme" class-name="contentClassName" label="领料单号">{{tableData.docno  }}</el-descriptions-item>
        <el-descriptions-item label-class-name="labelClassNAme" class-name="contentClassName" label="生产工单编号">{{tableData.production_no }}</el-descriptions-item>
        <el-descriptions-item label-class-name="labelClassNAme" class-name="contentClassName" label="状态">{{ statusFormatter[tableData.kingdee_status]  }}</el-descriptions-item>
      </el-descriptions>
    </div>
  <!-- </div> -->

  <div id="details" ref="details">
    <el-tabs v-model="activeName" class="demo-tabs" >
      <el-tab-pane label="生产领料单明细" name="details">
        <el-table :data="detailData" border>
          <!-- <el-table-column prop="id" label="工艺id" width="70" /> -->
          <!-- <el-table-column prop="order_id" label="关联单据id" width="100" /> -->
          <el-table-column prop="row_num" label="原单行号" min-width="100" />
          <el-table-column prop="material_no" label="品号" min-width="180" />
          <el-table-column prop="material.fname" label="品名" min-width="180" />
          <el-table-column prop="material.fspecification" label="规格" min-width="180" />
            <el-table-column prop="material.funit_name" label="单位编码" width="150" />
            <el-table-column prop="qty" label="领料数量" width="120" >
                <template #default="scope">{{ Number(scope.row.qty) }}</template>
            </el-table-column>
            <el-table-column prop="lot_num" label="领料箱号" min-width="200" />
            <el-table-column prop="wms_code" label="仓库代码" width="150" />
            <el-table-column prop="location.wms.fname" label="仓库名称" width="150" />
            <el-table-column prop="location.warehousecode" label="库位代码" width="150" />
            <el-table-column prop="location.repositoryname" label="库位名称" width="150" />
          <el-table-column prop="creator" label="创建者" min-width="130" />
          <el-table-column prop="created_at" label="创建时间" min-width="170" />
          <el-table-column prop="updated_at" label="更新时间" min-width="170" />
        </el-table>

        <Paginate />
      </el-tab-pane>
      <el-tab-pane label="生产领料单汇总" name="detailsAll">
        <el-table :data="detailAllData" border>
            <el-table-column prop="row_num" label="原单行号" min-width="150" />
            <el-table-column prop="production_no" label="工单编号" min-width="180" />
            <el-table-column prop="material_no" label="品号" min-width="180" />
            <el-table-column prop="material.fname" label="品名" min-width="180" />
            <el-table-column prop="material.fspecification" label="规格" min-width="180" />
            <el-table-column prop="material.funit_name" label="单位名称" width="150" />
            <el-table-column prop="qty" label="领料数量" width="120" >
            <template #default="scope">{{ Number(scope.row.qty) }}</template>
          </el-table-column>
            <el-table-column prop="wms_code" label="仓库代码" width="150" />
            <el-table-column prop="wms.fname" label="仓库名称" width="150" />


        </el-table>

        <Paginate />
      </el-tab-pane>
    </el-tabs>
  </div>

</div>
</div>

</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import { useRouter, useRoute } from 'vue-router'
import http from '/admin/support/http'

const router = useRouter()
const route = useRoute()

const api = `production/pick/order/${route.query.id}`
const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

console.log('获取到的tableData：',tableData)
// const rowInfo = JSON.parse(route.query.rowInfo)
// console.log(rowInfo)

const detailData = ref([])

const getDetail = () => {
  // /aip/production/pick/detail?order_id=领料单id
  const api2 = `production/pick/detail?order_id=${route.query.id}?`
  http.get(api2).then(r => {
    console.log(r.data.data)
    detailData.value = r.data.data
  })
}

getDetail()

const detailAllData = ref([])


const getDetailAll = () => {
  // /aip/production/pick/detail?order_id=领料单id
  const api2 = `production/pick/group/by?order_id=${route.query.id}`
  http.get(api2).then(r => {
    console.log('请求汇总数据：',r.data.data)
    detailAllData.value = r.data.data
  })
}

getDetailAll()


const statusFormatter = {
  0:'待推送',
  1:'推送成功',
  2:'推送失败'
}



const searchbox = ref(null)


// console.log('路由参数接收', route.query.id)

const backHandler = () => {
  router.push('/production/pickOrder')
}

const activeName = ref('details')
const base = ref(null)
const details = ref(null)
const content = ref()

onMounted(() => {
  search()
  deleted(reset)
})
</script>

<style lang="css">
/* .content{
  border: 2px solid red;
 overflow:hidden;
} */
.backBtn {
  margin: 20px 10px;
}

h2 {
  font-weight: bold;
}
#base {
  margin-bottom: 30px;
  /* border: 2px solid green; */
}
#details {
  /* border: 2px solid pink; */
}

.tabs {
  padding: 10px 0 0;
  /* border: 2px solid #000; */
  z-index: 999;
  background-color: #fff;
  position: sticky;
  top: -15px;
}

.tagRow {
  display: inline-block;
  /* border: 1px solid #000; */
  margin: 20px 10px;
}

.tagRow ul {
  display: flex;
  border: 1px solid #eee;
}
.tagRow ul li {
  margin: 0 5px;
  /* border: 1px solid #eee; */
  padding: 5px 10px;
  /* border-radius: 5px; */
}
.active {
  background-color: #409eff;
  color: #fff;
}
.labelClassNAme {
  width: 130px;
}
.contentClassName {
  width: 170px;
}
</style>
